package com.spring.hotel.controller;

import com.spring.hotel.common.JsonResponse;
import com.spring.hotel.entity.Employee;
import com.spring.hotel.entity.PageDTO;
import com.spring.hotel.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hotel/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    //添加
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public JsonResponse insert(@RequestBody Employee employee) {
        employeeService.save(employee);
        return JsonResponse.success(null);
    }

    //修改
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    public JsonResponse updateUser(@RequestBody Employee employee) throws Exception {
        employeeService.updateById(employee);
        return JsonResponse.success(null);
    }

    //删除
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
    public JsonResponse delete(@PathVariable String id) {
        employeeService.removeById(id);
        return JsonResponse.success(null);
    }

    //分页查询
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JsonResponse list(Employee employee, PageDTO pageDTO) {
        return employeeService.pageList(employee,pageDTO);
    }
}
